<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>注册</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta http-equiv="Access-Control-Allow-Origin" content="*">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link href="./lib/layui-v2.5.5/css/layui.css"  rel="stylesheet"/>
		<script src="./lib/layui-v2.5.5/layui.js"></script>
	</head>
	<body>	
		<div class="layui-container">
			<div class="layui-row">
				<h1 style="text-align: center;margin: 3%;">注册信息</h1>
			</div>
			<div id="register" class="layui-row">
				<div class="layui-col-md8 layui-col-md-offset2">
				<form class="layui-form">
				  <div class="layui-form-item">
					<label class="layui-form-label">姓名</label>
					<div class="layui-input-inline">
					  <input type="text" name="name" id="name" required  lay-verify="required"  autocomplete="off" class="layui-input">
					</div>
				  </div>
				  <div class="layui-form-item">
					<label class="layui-form-label">登陆密码</label>
					<div class="layui-input-inline">
					  <input type="password" id="password" name="password" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
					</div>					
				 </div>
				 <div class="layui-form-item">
					 <label class="layui-form-label">确认密码</label>
					 	<div class="layui-input-inline">
					 	  <input type="password" id="repassword" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
					 </div>
				 </div>
				 <div class="layui-form-item">
					<label class="layui-form-label">个人电话</label>
					<div class="layui-input-inline">
					  <input type="text" name="phone" id="phone" required  lay-verify="required|phone" placeholder="" autocomplete="off" class="layui-input">
					</div>
				  </div>	
				<div class="layui-form-item">
					<label class="layui-form-label">地址</label>
					<div class="layui-input-inline">
					  <input type="text" name="address" id="address" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
					</div>
				 </div>			   
				  <div class="layui-form-item">
					<div class="layui-input-block">
					  <button class="layui-btn" lay-submit lay-filter="registersubmit">注册</button>
					  <button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				  </div>
					</form>				
				</div>							
			</div>			
		</div>
		
		
		<script>
			layui.use(['form','jquery','layer'], function(){
			  var form = layui.form,
				  $ = layui.jquery,
				  layer = layui.layer;
			  //监听提交
			  form.on('submit(registersubmit)', function(){		
				var userInfo = {
					uid : 0,
					username : $("#name").val(),
					password : $("#password").val(),
					phone : $("#phone").val(),
					address : $("#address").val()  
				};
				if($("#password").val() == $("#repassword").val()){
					$.ajax({
						url:"http://localhost:9906/selluser/add",
						type:'post',
						data:JSON.stringify(userInfo),
						dataType:'json',
						contentType: "application/json",
						success:function(data){
							if(data.code == 100){
								layer.msg(data.msg,{icon: 5});//失败的表情
								return;
							}else if(data.code == 200){
								layer.msg("注册成功，快登陆吧！", {
									icon: 6,//成功的表情
									time: 2000 //1秒关闭（如果不配置，默认是3秒）
								}, function(){
									window.location.href="./login.html";
								});
							}
						}						
					});			
				}else{
					layer.alert("两次密码不一致！");
				}
						
				return false;//阻止表单跳转
			  });
			});
			
			layui.use(['laydate'], function(){
			  var laydate = layui.laydate;		
			  //执行一个laydate实例
			  laydate.render({
				elem: '#starttime' //指定元素
				,theme: 'molv'
				,trigger:'click'
			  });
			  laydate.render({
				elem: '#grade'
				,type: 'year'
				,theme: 'molv'
				,trigger:'click'
			  });
			});		
		</script>
	</body>
</html>
